package leetcode.erfen;

import java.util.Random;

public class Test3 {
    public static void main(String[] args) {
        int[] num = {-1, 0, 3, 5, 9, 12};
        System.out.println(search(num, 9));
    }

    public static int search(int[] nums, int target) {
        int left = 0, right = nums.length - 1;
        int index = -1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (nums[mid] == target) {
                index = mid;
                break;
            } else if (nums[mid] < target) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return index;
    }
}
